<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="类型" prop="billType">
        <el-select v-model="queryParams.billType" placeholder="请选择0-龙钞 1-蛇钞" clearable>
          <el-option
            v-for="dict in dict.type.money_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="冠字号" prop="serialNumber">
        <el-input
          v-model="queryParams.serialNumber"
          placeholder="请输入冠字号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="numberType">
        <el-select v-model="queryParams.numberType" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.number_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>




      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table height="500px" v-loading="loading" :data="niceRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">未上架</span>
          <span v-if="scope.row.status === 1">已上架</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="billType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.money_type" :value="scope.row.billType"/>
        </template>
      </el-table-column>
      <el-table-column label="冠字号" align="center" prop="serialNumber" />
      <el-table-column label="类别" align="center" prop="numberType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.number_type" :value="scope.row.numberType"/>
        </template>
      </el-table-column>
      <el-table-column label="连续个数" align="center" prop="numberCount" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="拥有者账号" align="center" prop="owner" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:niceRecord:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>



    <!-- 添加或修改靓号记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="是否上架 1-上架 0-下架" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="0-龙钞 1-蛇钞" prop="billType">
          <el-select v-model="form.billType" placeholder="请选择0-龙钞 1-蛇钞">
            <el-option
              v-for="dict in dict.type.money_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="冠字号" prop="serialNumber">
          <el-input v-model="form.serialNumber" placeholder="请输入冠字号" />
        </el-form-item>
        <el-form-item label="0-单张 1-标十 2-标百 3-连续号" prop="numberType">
          <el-select v-model="form.numberType" placeholder="请选择0-单张 1-标十 2-标百 3-连续号">
            <el-option
              v-for="dict in dict.type.number_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="连续个数" prop="numberCount">
          <el-input v-model="form.numberCount" placeholder="请输入连续个数" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="拥有者账号" prop="owner">
          <el-input v-model="form.owner" placeholder="请输入拥有者账号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNiceRecord, getNiceRecord, delNiceRecord, addNiceRecord, updateNiceRecord } from "@/api/system/niceRecord";

export default {
  name: "NiceRecord",
  dicts: ['number_type', 'money_type', 'sys_yes_no'],
  data() {
    return {      // 0-裸 1-ACG 2-PMG 3-PCGS
      nakedOrGradeds:[
        {value:0,name:'裸币'},
        {value:1,name:'ACG'},
        {value:2,name:'PMG'},
        {value:3,name:'PCGS'}
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 靓号记录表格数据
      niceRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        billType: '0',
        serialNumber: null,
        numberType: null,
        numberCount: null,
        price: null,
        owner: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "是否上架 1-上架 0-下架不能为空", trigger: "change" }
        ],
        billType: [
          { required: true, message: "0-龙钞 1-蛇钞不能为空", trigger: "change" }
        ],
        serialNumber: [
          { required: true, message: "冠字号不能为空", trigger: "blur" }
        ],
        numberType: [
          { required: true, message: "0-单张 1-标十 2-标百 3-连续号不能为空", trigger: "change" }
        ],
        numberCount: [
          { required: true, message: "连续个数不能为空", trigger: "blur" }
        ],
        owner: [
          { required: true, message: "拥有者账号不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询靓号记录列表 */
    getList() {
      this.loading = true;
      listNiceRecord(this.queryParams).then(response => {
        this.niceRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: null,
        billType: null,
        serialNumber: null,
        numberType: null,
        numberCount: null,
        price: null,
        owner: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加靓号记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNiceRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改靓号记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNiceRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNiceRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除靓号记录编号为"' + ids + '"的数据项？').then(function() {
        return delNiceRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/niceRecord/export', {
        ...this.queryParams
      }, `niceRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
